package com.yuexunit.operationman.nbsy.module.OperationBeforeAndAfter.ui;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.base.BaseKJActivity;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.OperationBeforeAndAfter.BeforeAndAfterContracts;
import com.yuexunit.operationman.nbsy.module.OperationBeforeAndAfter.bean.BeforeAndAfterBean;
import com.yuexunit.operationman.nbsy.module.OperationBeforeAndAfter.model.impl.BeforeAndAfterDetailModel;
import com.yuexunit.operationman.nbsy.module.OperationBeforeAndAfter.presenter.IBeforeAndAfterDetailPresenter;
import com.yuexunit.operationman.nbsy.module.OperationBeforeAndAfter.presenter.impl.BeforeAndAfterDetailPresenter;
import com.yuexunit.operationman.nbsy.module.OperationBeforeAndAfter.ui.view.IBeforeAndAfterDetailView;
import com.yuexunit.operationman.nbsy.widget.LoadingDialog;

import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chenss on 2017/11/7 0007.
 */

public class Act_OperationBeforeAndAfter_Main extends BaseKJActivity implements IBeforeAndAfterDetailView {

    @Bind(R.id.titlebar_tv_title)
    TextView titlebarTvTitle;
    @Bind(R.id.usr_head)
    ImageView usrHead;
    @Bind(R.id.usr_name)
    TextView usrName;
    @Bind(R.id.usr_age)
    TextView usrAge;
    @Bind(R.id.usr_gender)
    TextView usrGender;
    @Bind(R.id.ops_date)
    TextView opsDate;
//    @Bind(R.id.ops_room)
//    TextView opsRoom;
    @Bind(R.id.preops_diagnosis)
    TextView preopsDiagnosis;
    @Bind(R.id.position)
    TextView position;
    @Bind(R.id.recipe_date)
    TextView recipeDate;
    @Bind(R.id.recipe_id)
    TextView recipeId;
    @Bind(R.id.hisPatientNo)
    TextView hisPatientNo;

    IBeforeAndAfterDetailPresenter presenter;
    LoadingDialog loadingDialog;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_operationbeforeandafter_main);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        setTitle();
        loadingDialog = new LoadingDialog(this);
        presenter = new BeforeAndAfterDetailPresenter(this,new BeforeAndAfterDetailModel());
    }

    @Override
    public void onResume(){
        super.onResume();
        Map<String, String> params = new HashMap<>();
        params.put("operationNo", PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_OPERATION_ID)+"");
        presenter.getBeforeAndAfterDate(params);
    }


    private void setTitle()
    {
        titlebarTvTitle.setText("术前访视、术后随访单");
    }

    @OnClick({R.id.titlebar_img_back, R.id.ops_pre, R.id.ops_end, R.id.sign, R.id.preview})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.titlebar_img_back:
                finish();
                break;
            case R.id.ops_pre:
                startActivity(new Intent(this, Act_OperationBeforeAndAfter_BeforeVisit.class));
                break;
            case R.id.ops_end:
                startActivity(new Intent(this, Act_OperationBeforeAndAfter_AfterVisit.class));
                break;
            case R.id.sign:
                startActivity(new Intent(this, Act_OperationBeforeAndAfter_Sign.class));
                break;
            case R.id.preview:
                startActivity(new Intent(this, Act_OperationBeforeAndAfter_Preview.class));
                break;
        }
    }

    @Override
    public void getBeforeAndAfterDate(BeforeAndAfterBean beforeAndAfterBean) {
        if(beforeAndAfterBean.getCode() == 200)
        {
            AppConfig.BEFOREANDAFTERBEAN =beforeAndAfterBean;
            usrName.setText(AppConfig.BEFOREANDAFTERBEAN.getObject().getName());
            usrAge.setText(AppConfig.BEFOREANDAFTERBEAN.getObject().getAge());
            if(AppConfig.BEFOREANDAFTERBEAN.getObject().getSex().equals("1")) {
                usrGender.setText("男");
            }else if(AppConfig.BEFOREANDAFTERBEAN.getObject().getSex().equals("2"))
            {
                usrGender.setText("女");
            }
            else {
                usrGender.setText("不详");
            }
            opsDate.setText(AppConfig.BEFOREANDAFTERBEAN.getObject().getOperationTime());
            preopsDiagnosis.setText(AppConfig.BEFOREANDAFTERBEAN.getObject().getPreoperativeDiagnosis());
            position.setText(AppConfig.BEFOREANDAFTERBEAN.getObject().getLesion());
            recipeDate.setText(AppConfig.BEFOREANDAFTERBEAN.getObject().getOperationName());
            recipeId.setText(AppConfig.BEFOREANDAFTERBEAN.getObject().getBedNo());
            hisPatientNo.setText(AppConfig.BEFOREANDAFTERBEAN.getObject().getVisitNo());
            if(AppConfig.BEFOREANDAFTERBEAN.getObject().getBeforeNursing() == null)
            {
                AppConfig.BEFOREANDAFTERBEAN.getObject().setBeforeNursing(BeforeAndAfterContracts.BEFORE_NURSING_ENTITY(this));
            }

            if(AppConfig.BEFOREANDAFTERBEAN.getObject().getAfterNursing() == null)
            {
                AppConfig.BEFOREANDAFTERBEAN.getObject().setAfterNursing(BeforeAndAfterContracts.AFTER_NURSING_ENTITY(this));
            }

//            if(AppConfig.BEFOREANDAFTERBEAN.getObject().get_id() == null)
//            {
//                AppConfig.BEFOREANDAFTERBEAN.getObject().set_id(BeforeAndAfterContracts.ID_ENTITY(this));
//            }
            Log.e("jx","jx");
        }
    }

    @Override
    public void loadingDialogStatus(int status) {
        switch (status) {
            case AppConfig.SHOW_DIALOG:
                loadingDialog.setCanceledOnTouchOutside(false);
                loadingDialog.show();
                break;
            case AppConfig.DISMISS_DIALOG:
                loadingDialog.dismiss();
                break;

        }
    }
}
